package com.situ.day2;

import org.junit.Test;

import java.util.Scanner;

public class array {

    @Test
    public  void t1(){
        int[] array1 = new int[5];
        array1[0] = 5;
        array1[1] = 8;
        array1[2] = 66;
        array1[3] = 53;
        array1[4] = 128;
        int max = array1[0];
        for (int i = array1.length - 1; i >= 0; i--){
            System.out.println(array1[i]);
            if (max < array1[i]) {
                max = array1[i];
            }
        }
        System.out.println(max);
    }

    @Test
    public void t2(){
        int[] ar = new int[]{40,17,21,1};
        for (int i = 0; i < ar.length - 1; i++){
            for (int j = 0; j <ar.length - 1 - i;j++){
                if (ar[j] > ar[j + 1]){
                    int temp = ar[j + 1];
                    ar[j + 1] = ar[j];
                    ar[j] = temp;
                }
            }
            for (int k = 0; k < ar.length; k++){
                System.out.print(ar[k] + "\t");
            }
            System.out.println(" ");
        }
    }

    @Test
    public void t3(){
        int[] scores = new int[]{0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        System.out.println(scores.length);
        int sum = 0;
        for(int m = 0; m <= 9; m++) {
            for (int k = 0; k < scores.length; k++) {
                if (scores[k] == m) {
                    sum++;
                }
            }
            System.out.print("数字" + m);
            System.out.print("有：");
            System.out.println(sum);
            sum = 0;
        }
    }

    @Test
    public void t4(){
        int[] scores = new int[]{0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 0; i < scores.length; i++){
            if (scores[i] % 2 == 0 && scores[i] != 0){
                sum2++;
            }else if(scores[i] == 0){
            }else {
                sum1++;
            }
        }
        System.out.println("奇数：" + sum1);
        System.out.println("偶数:"  + sum2);
    }

    @Test
    public void t5(){
        int[] sc = new int[3];
        int sum = 0;
        int count = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入学生1成绩");
        sc[0] = scanner.nextInt();
        System.out.println("输入学生2成绩");
        sc[1] = scanner.nextInt();
        System.out.println("输入学生3成绩");
        sc[2] = scanner.nextInt();
        for (int i = 0; i < sc.length; i++){
            sum = sum + sc[i];
            count++;
        }
        System.out.println(sum / count);
    }

    @Test
    public void t7(){
        System.out.println("B,,D,,A,,C,,A,,第十题C，，B,,C,,B");

    }

    @Test
    public void t8(){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        char[] array = str.toCharArray();
        boolean ishuiwen = true;
        for (int i = 0 ; i < array.length / 2; i++){
             if(array[i] != array[array.length - 1 - i]){
                 ishuiwen = false;
                 break;
             }
        }
        System.out.println(ishuiwen ? "是回文" : "不是回文") ;


    }

    @Test
    public void t9(){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        System.out.println(str);
        char[] array = str.toCharArray();
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        int count4 = 0;
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            System.out.print("\t");
            if((array[i] >= 'a' && array[i] <= 'z') || (array[i] >= 'A' && array[i] <= 'Z')){
                count1++;
            } else if(array[i] >= '0' && array[i] <= '9'){
                count2++;
            } else if(array[i] == ' '){
                count3++;
            } else{
                count4++;
            }
        }
        System.out.println();
        System.out.println(count1);
        System.out.println(count2);
        System.out.println(count3);
        System.out.println(count4);

    }

    @Test
    public void t11(){
        Scanner scanner = new Scanner(System.in);
        double mon = scanner.nextDouble();
        double prize;
        if (mon <= 10) {
            prize = mon * 0.1;
            System.out.println(prize);
        }else if (mon >= 10 && mon <= 20){
            prize = (mon - 10) * 0.075 + 1;
            System.out.println(prize);
        } else if(mon >= 20 && mon <= 40){
            prize = (mon - 20) * 0.05 + 1 + 0.75;
            System.out.println(prize);
        } else if(mon >= 40 && mon <= 60){
            prize = (mon - 40) * 0.03 + 2.75;
            System.out.println(prize);
        } else if(mon >= 60 && mon <= 100){
            prize = (mon - 60) * 0.015 + 3.05;
            System.out.println(prize);
        } else if(mon > 100){
                prize = (mon - 100) * 0.01 + 3.65;
                System.out.println(prize);
        } else {
            System.out.println("输入信息错误");
        }
    }

    @Test
    public void t12(){
        for (int i = 1; i <= 5; i++) {
            for (int j = 5; j >= i; j--){
                System.out.print("*");
            }
            System.out.println();
        }
    }

    @Test
    public void t13(){
        int a = (int) (Math.random() *10);
        System.out.println(a);
        int sum1 = a;
        int count = 1;
        int sum2 = a;
        for (int i = 1; i <= (2 * a - 1); i++){
            count = 10 * count;
            sum1 = count * a + sum1;
            System.out.println(sum1);
            sum2 =sum2 + sum1;
        }
        System.out.println(sum2);
    }

    @Test
    public void t16(){
        int[] array = new int[10];
        Scanner scanner = new Scanner(System.in);
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        for (int i = 0;i < 10; i++){
            System.out.println("请输入成绩：");
            array[i] = scanner.nextInt();
        }
        for (int j = 0; j <  10; j++){
            if (array[j] == 100){
                count1++;
            } else if (array[j] >= 90 && array[j] <= 99){
                count2++;
            } else if (array[j] >= 80 && array[j] <= 89){
                count3++;
            }
        }
        System.out.println(count1);
        System.out.println(count2);
        System.out.println(count3);
    }




}
